package com.itheima.listener.config;


import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ErrorMessageConfig {

    /****
     * 交换机
     */
    @Bean
    public DirectExchange errorMessageExchange() {
        return new DirectExchange("error.direct");
    }

    /****
     * 队列
     */

    @Bean
    public Queue errorQueue() {
        return new Queue("error.queue");
    }

    /****
     * 绑定队列和交换机
     */
    @Bean
    public Binding errorbinding(Queue errorQueue, DirectExchange errorMessageExchange) {
        return BindingBuilder.bind(errorQueue).to(errorMessageExchange).with("error");
    }
    @Bean
    public MessageRecoverer republishMessageRecoverer(RabbitTemplate rabbitTemplate){
        return  new RepublishMessageRecoverer(rabbitTemplate,"error.direct","error");
    }

    /****
     * 第二个队列
     */
//    @Bean
//    public Queue fanoutQueue() {
//        return new Queue("fanout.queue2");
//    }
//
//    /****
//     * 绑定队列和交换机
//     */
//    @Bean
//    public Binding bindingQueue(Queue fanoutQueue2, FanoutExchange fanoutExchange) {
//        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
//    }
}
